﻿// Application Namespace
var Application = {
	Data : {},
	Models : {},
	Collections : {},
	Views : {},
	Config : {}
};

Application.Model = Backbone.Model.extend({
	get: function(attr) {
		if(_.isFunction(this.getters[attr])) {
			return this.getters[attr].call(this);
		}

		return Backbone.Model.prototype.get.call(this, attr);
	},
	
	toJSON: function() {
		var attr = Backbone.Model.prototype.toJSON.call(this);
		
		for(node in attr) {
			if(_.isFunction(this.getters[node])) {
				attr[node] = this.getters[node].call(this);
			}
			
			if(_.identity(attr[node]) instanceof Backbone.Model) {
				attr[node] = attr[node].toJSON();
			}			
		}
		
		return attr;
	},

	getters: { }
});